package vista;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;

import negocio.beans.central.OrdenDeCompra;
import negocio.beans.central.RemitoProveedor;
import negocio.beans.oficinaventa.Item;
import xml.XMLClass;
import controlador.CasaCentral;


public class RecepcionMercaderia extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;
	private JLabel lblXML;
	private JLabel lblFinal;
	private JLabel lblResultado;
	private JButton btnAceptar;
	private JTextField txtNombreXML;

	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				RecepcionMercaderia inst = new RecepcionMercaderia();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public RecepcionMercaderia() {
		super();
		initGUI();
		CentrarJFrame();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(202,203,251));
			this.setTitle("Recepcion de Mercaderia");
			this.setResizable(false);
			{
				lblXML = new JLabel();
				getContentPane().add(lblXML);
				lblXML.setText("Nombre XML:");
				lblXML.setBounds(19, 37, 104, 16);
			}
			{
				txtNombreXML = new JTextField();
				getContentPane().add(txtNombreXML);
				txtNombreXML.setBounds(118, 34, 149, 23);
			}
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar);
				btnAceptar.setText("Aceptar");
				btnAceptar.setBounds(135, 74, 108, 23);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						XMLClass xml = new XMLClass();
						RemitoProveedor r = xml.fremitoProveedor(txtNombreXML.getText());
						
						boolean exito = CasaCentral.getInstancia().RecepcionMercaderia(r);
						
						if(exito){
							lblFinal.setText("Los rodamientos del remito coinciden con la Orden de Compra emitida");
							lblFinal.setForeground(new Color(0,0,0));
								
						}else{
							lblFinal.setText("Los rodamientos del remito no coinciden con la Orden de Compra emitida");
							lblFinal.setForeground(new Color(255,0,0));
						}
					}
				});
			}
			{
				lblResultado = new JLabel();
				getContentPane().add(lblResultado);
				lblResultado.setText("Resultado:");
				lblResultado.setBounds(12, 125, 288, 16);
				lblResultado.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lblResultado.setHorizontalAlignment(SwingConstants.CENTER);
			}
			{
				lblFinal = new JLabel();
				getContentPane().add(lblFinal);
				lblFinal.setBounds(12, 158, 288, 16);
				lblFinal.setHorizontalAlignment(SwingConstants.CENTER);
			}
			pack();
			this.setSize(328, 223);
		} catch (Exception e) {
		   
			e.printStackTrace();
		}
	}
	
	private void CentrarJFrame(){
		
	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	    
	    
	    int w = this.getSize().width;
	    int h = this.getSize().height;
	    int x = (dim.width-w)/2;
	    int y = (dim.height-h)/2;
	    
	    
	    this.setLocation(x, y);
	}

}
